﻿-var t_dt = ViewData["DataTable"] as DataTable
-var hidecb = ViewData.ContainsKey("hidecb")
-var t_cols = ViewData["Columns"] as List<Column>
-var t_viscols = ViewData["VisibleColumns"] as Column[]
-string t_pk = ViewData.ContainsKey("PrimaryKey") ? ViewData["PrimaryKey"].ToString() : null
=HTMLHelper.HiddenInput("tablecontroller",ViewData["Controller"])
=HTMLHelper.HiddenInput("tableaction",ViewData["Action"])
-bool trackchanges = ViewData.ContainsKey("trackchanges")
_error
%table.data{width="100%"}
  %tr
    -if(t_pk != null && !hidecb)
      %th.cb{width="1%"}
        %input#rowids.cb{type="checkbox",onclick="selectAll(this.checked)"}
    -foreach(var t_c in t_viscols)
      %th{width=string.Format("{0}%",t_c.Width),title=t_c.Title,class=(t_c.Sortable && t_c.SortDirection != SortDirection.None) ? "sorted":""}
        %nobr
          -if(t_c.Sortable)
            %a{href="#",onclick=String.Format("return orderBy('{0}')",t_c.SortExpression)}=(t_c.ShortTitle ?? t_c.Title)
            -if(t_c.SortDirection != SortDirection.None)
              =t_c.SortDirection==SortDirection.Ascending?"&darr;":"&uarr;"
            -else
              ="&nbsp;&nbsp;"
          -else
            =(t_c.ShortTitle ?? t_c.Title)
  -bool odd = true
  -DataRow prev_dr = null
  -bool hasRowClass = t_dt.Columns.Contains("RowClass")
  -foreach(DataRow t_dr in t_dt.Rows)
    -odd = !odd
    %tr{class=(odd ? "odd " : "") + (hasRowClass ? t_dr["RowClass"].ToString() : "")}
      -if(t_pk!=null && !hidecb)
        %td.cb=HTMLHelper.Checkbox("id",t_dr[t_pk],"rowid cb",false,true)
      -foreach(var t_c in t_viscols)
        -string t_class = t_c.CssClass
        -if(trackchanges && prev_dr != null && !object.Equals(prev_dr[t_c.Id],t_dr[t_c.Id])) t_class += " yellowbg"
        -if(!string.IsNullOrEmpty(t_c.TdId))
          %td{class=t_class,id=t_c.TdId+t_dr[t_pk]}=t_dr[t_c.Id]
        -else
          %td{class=t_class}=t_dr[t_c.Id]
    -prev_dr = t_dr
  -if(ViewData.ContainsKey("Total"))
    -var total = ViewData["Total"] as Dictionary<string,decimal>
    %tr.total
      -if(t_pk!=null && !hidecb)
        %td &nbsp;
      -foreach(var t_c in t_viscols)
        %td
          -if(t_c.CountTotal)
            =total[t_c.Id]
_table/pagination
